<?php

class Member_model extends MY_Model {

    public function __construct() {
        parent::__construct();
        $this->table = 'jg_member';
    }

    public function frontend_records($limit = 0, $offset = 0, $conditions = array()) {
        $lang = $this->input->cookie('lang') == 'en' ? '_en' : '';
        $select_string = "m.id as id ,m.name{$lang} as name,m.link as link";
        $this->db->select($select_string);
        $this->db->from($this->table . ' m');

        if (isset($conditions[0])) {
            foreach ($conditions as $condition) {
                $this->db->where($condition[0], $condition[1]);
            }
        }
        if ($limit) {
            $this->db->limit($limit, $offset);
        }

        $query = $this->db->get();
        return $query->result();
    }

    public function frontend_find($id) {
        $lang = $this->input->cookie('lang') == 'en' ? '_en' : '';
        $select_string = "m.id as id ,m.name{$lang} as name,m.link as link";
        $this->db->select($select_string);
        $this->db->from($this->table . ' m');
        $this->db->where('m.id', $id);
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->row_object();
    }

}
